home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Base / sa / aval < prev    next >
Text File  |  1996-04-14  |  4KB  |  103 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  3. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  4. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  5. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  6. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  7. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  8.  
  9. -- aval.sa: Built-in value arrays, only for inclusion.
  10.  
  11. -------------------------------------------------------------------
  12. immutable class AVAL{T} is
  13.    -- Built-in value arrays of elements of type T. Only exists for
  14.    -- inclusion by other value types. They must redefine `asize' to
  15.    -- get a non-trivial array portion. Array indices start at 0 and
  16.    -- go up to "asize-1". Together with BOOL this is the
  17.    -- fundamental class for the construction of objects. All feature 
  18.    -- names begin with "a" to minimize name conflicts when included.
  19.    
  20.    const asize:INT:=0;
  21.       -- The number of elements of type T in self. Must be redefined as 
  22.       -- a constant in the including class. The compiler will generate
  23.       -- a standard constant, plus a #define with the name of
  24.       -- the class and _ASIZE appended (ex: AVALINT_ASIZE)
  25.       -- Apart from this special macro this constant is not 
  26.       -- special to the compiler
  27.  
  28.    aget(ind:INT):T 
  29.       -- The element of self with index `ind'. Built-in.
  30.       pre ind.is_bet(0,asize-1) is 
  31.     builtin AVAL_AGET; end;
  32.  
  33.    aset(ind:INT,val:T):SAME 
  34.       -- Return a copy of self with the component with index `ind' set 
  35.       -- to `val'. Built-in. 
  36.       pre ind.is_bet(0,asize-1) is 
  37.          builtin AVAL_ASET; end;
  38.  
  39.    aelt!:T is
  40.       -- Yield each element of self in order. Built-in.
  41.       builtin AVAL_AELTB; end;
  42.  
  43.    aelt!(once beg:INT):T
  44.       -- Yield each element of self starting at `beg'. Built-in.
  45.       pre beg.is_bet(0,asize-1) is
  46.          builtin AVAL_AELT_BEGB;
  47.       end;
  48.    
  49.    aelt!(once beg,once num:INT):T
  50.       -- Yield `num' successive elements of self starting at
  51.       -- index `beg'. Built-in.
  52.       pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg) is
  53.          builtin AVAL_AELT_BEG_NUMB; end;
  54.  
  55.    private is_legal_aelts_arg(beg,num,step:INT):BOOL is
  56.       -- True if the arguments are legal values for `aelts'.
  57.       return beg.is_bet(0,asize-1) and
  58.          ((step>0 and num.is_bet(0,(asize-beg+step-1)/step)) or
  59.           (step<0 and num.is_bet(0,(beg-step)/-step))) end;
  60.    
  61.    aelt!(once beg,once num,once step:INT):T
  62.       -- Yield `num' elements of self starting at `beg' and stepping
  63.       -- by `step' which must not be zero. Built-in.
  64.       pre is_legal_aelts_arg(beg,num,step) is
  65.       builtin AVAL_AELT_BEG_NUM_STEPB; end;
  66.    
  67.    acopy_from(beg:INT,src:SAME):SAME 
  68.       -- Return a copy of self modified by copying elements from `src'
  69.       -- into locations with indices starting at `beg'. Built-in.
  70.       pre beg.is_bet(0,asize-1) is
  71.       -- r::=self; 
  72.       -- loop r:=r.aset(beg.upto!(asize-1),src.aelt!) end;
  73.       -- return r end;
  74.       builtin AVAL_ACOPY; end;
  75.    
  76.    acopy_from(beg,num:INT,src:SAME):SAME
  77.       -- Return a copy of self modified by copying `num' elements from 
  78.       -- `src' into locations with indices starting at `beg'. Built-in.   
  79.       pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg) is
  80.       -- r::=self; 
  81.       -- loop r:=r.aset(beg.upto!(beg+num-1),src.aelt!) end;
  82.       -- return r end;      
  83.       builtin AVAL_ACOPY_BEG_NUM; end;
  84.    
  85.    acopy_from(beg,num,srcbeg:INT,src:SAME):SAME
  86.       -- Return a copy of self modified by copying `num' elements from 
  87.       -- `src' starting at index `srcbeg' into locations with indices 
  88.       -- starting at `beg'. Built-in.      
  89.       pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg)
  90.          and num<src.asize-srcbeg is   
  91.       -- r::=self; 
  92.       -- loop r:=r.aset(beg.upto!(beg+num-1),src.aelt!(srcbeg)) end;
  93.       -- return r end;            
  94.       builtin AVAL_ACOPY_BEG_NUM_SRCBEG; end;
  95.    
  96.    aind!:INT is
  97.       -- Yield the indices of self in order. Built-in.
  98.       builtin AVAL_AINDB; end;
  99.  
  100. end; -- class AVAL{T}
  101.  
  102. -------------------------------------------------------------------
  103.